myApp.controller('purchaseNewGoods', ['$scope', '$http', '$shop', function($scope, $http, $shop){

	$scope.allStorage = [];
	$http.get('searchAllStorage').then(function successCallback(response) {
		$scope.allStorage = response.data;
	}, function errorCallback(response) {
		console.log("fail：" + response);
	});

	$scope.barcode = "";
	$scope.shopQuantity = "";
	$scope.storageId = "";
	$scope.storageQuantity = "";

	$scope.addShopStock = function() {

		if($scope.barcode === "") {
			alert("请填写条形码！");
			return;
		}
		if($scope.shopQuantity === "") {
			alert("请填写采购数量！");
			return;
		}

		var stockData = {
			"stock.stockId": $shop.myShop.shopId,
			"stock.type": 0,
			"stock.barcode": $scope.barcode,
			"stock.quantity": $scope.shopQuantity
		};

		var postCfg = {
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			transformRequest: function (data) {
				return $.param(data);
			}
		};

		$http.post('addStock', stockData, postCfg).then(function successCallback(response) {
			alert("已成功采购！");	
			$scope.barcode = "";
			$scope.shopQuantity = "";
			$scope.storageId = "";
			$scope.storageQuantity = "";

			console.log("ok：" + response);
		}, function errorCallback(response) {
			alert("采购失败！");
			console.log("fail：" + response);
		});	

	};

	$scope.addStorageStock = function() {

		if($scope.barcode === "") {
			alert("请填写条形码！");
			return;
		}
		if($scope.storageId === "") {
			alert("请选择仓库！");
			return;
		}
		if($scope.storageQuantity === "") {
			alert("请填写采购数量！");
			return;
		}

		var stockData = {
			"stock.stockId": $scope.storageId,
			"stock.type": 1,
			"stock.barcode": $scope.barcode,
			"stock.quantity": $scope.storageQuantity
		};

		var postCfg = {
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			transformRequest: function (data) {
				return $.param(data);
			}
		};

		$http.post('addStock', stockData, postCfg).then(function successCallback(response) {
			alert("已成功采购！");	
			$scope.barcode = "";
			$scope.shopQuantity = "";
			$scope.storageId = "";
			$scope.storageQuantity = "";

			console.log("ok：" + response);
		}, function errorCallback(response) {
			alert("采购失败！");
			console.log("fail：" + response);
		});	

	};

	$scope.cancle = function(type) {

		$scope.barcode = "";
		if(type === 0) {
			$scope.shopQuantity = "";			
		}else {
			$scope.storageId = "";
			$scope.storageQuantity = "";
		}

	};

}]);



myApp.controller('purchaseOldGoods', ['$scope', '$http', '$shop', function($scope, $http, $shop){

	$scope.allStorage = [];
	$http.get('searchAllStorage').then(function successCallback(response) {
		$scope.allStorage = response.data;
	}, function errorCallback(response) {
		console.log("fail：" + response);
	});

	$scope.barcode = "";
	$scope.shopQuantity = "";
	$scope.storageId = "";
	$scope.storageQuantity = "";

	$scope.addShopStock = function() {

		if($scope.barcode === "") {
			alert("请填写条形码！");
			return;
		}
		if($scope.shopQuantity === "") {
			alert("请填写采购数量！");
			return;
		}

		var stockData = {
			"stock.stockId": $shop.myShop.shopId,
			"stock.type": 0,
			"stock.barcode": $scope.barcode,
			"stock.quantity": $scope.shopQuantity
		};

		var postCfg = {
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			transformRequest: function (data) {
				return $.param(data);
			}
		};

		$http.post('addStockQuantity', stockData, postCfg).then(function successCallback(response) {
			alert("已成功采购！");	
			$scope.barcode = "";
			$scope.shopQuantity = "";
			$scope.storageId = "";
			$scope.storageQuantity = "";

			console.log("ok：" + response);
		}, function errorCallback(response) {
			alert("采购失败！");
			console.log("fail：" + response);
		});	

	};

	$scope.addStorageStock = function() {

		if($scope.barcode === "") {
			alert("请填写条形码！");
			return;
		}
		if($scope.storageId === "") {
			alert("请选择仓库！");
			return;
		}
		if($scope.storageQuantity === "") {
			alert("请填写采购数量！");
			return;
		}

		var stockData = {
			"stock.stockId": $scope.storageId,
			"stock.type": 1,
			"stock.barcode": $scope.barcode,
			"stock.quantity": $scope.storageQuantity
		};

		var postCfg = {
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			transformRequest: function (data) {
				return $.param(data);
			}
		};

		$http.post('addStockQuantity', stockData, postCfg).then(function successCallback(response) {
			alert("已成功采购！");	
			$scope.barcode = "";
			$scope.shopQuantity = "";
			$scope.storageId = "";
			$scope.storageQuantity = "";

			console.log("ok：" + response);
		}, function errorCallback(response) {
			alert("采购失败！");
			console.log("fail：" + response);
		});	

	};

	$scope.cancle = function(type) {

		$scope.barcode = "";
		if(type === 0) {
			$scope.shopQuantity = "";			
		}else {
			$scope.storageId = "";
			$scope.storageQuantity = "";
		}

	};

}]);



